package com.campus_information_portal.service.impl;

import com.campus_information_portal.dao.FinishProjectDao;
import com.campus_information_portal.entity.ProjectCondition;
import com.campus_information_portal.service.FinishProjectService;
import com.campus_information_portal.util.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 20155884 王晓阳
 * @className : FinishProjectImpl
 * @Description
 * @create 2018/05/31 10:10$
 **/
@Service
public class FinishProjectImpl implements FinishProjectService {
    @Autowired
    private FinishProjectDao finishProjectDao;

    /**
     * @param
     * @Description 学生查询已同意的立项
     * @author 20155884 王晓阳
     * @methodName
     * @returnType
     * @create 2018/5/31 10:11
     **/
    @Override
    public Message findAgreedProject(ProjectCondition projectCondition) {
        List<ProjectCondition> projectList = finishProjectDao.findAgreedProject(projectCondition);
        for (ProjectCondition p : projectList) {
            System.out.println("--" + p.getProjectName());
        }
        if (projectList.size() != 0) {
            return Message.success().add("projectList", projectList);
        }
        return Message.fail();
    }

    /**
     * @param
     * @Description 老师查询已同意的立项
     * @author 20155884 王晓阳
     * @methodName
     * @returnType
     * @create 2018/5/31 10:11
     **/
    @Override
    public Message findAgreedProjectByTea() {
        List<ProjectCondition> projectList = finishProjectDao.findAgreedProjectByTea();
        for (ProjectCondition p : projectList) {
            System.out.println("--" + p.getProjectName());
        }
        if (projectList.size() != 0) {
            return Message.success().add("projectList", projectList);
        }
        return Message.fail();
    }

    /**
     * @param
     * @Description 结项申请，更新状态为5，正在审核
     * @author 20155884 王晓阳
     * @methodName
     * @returnType
     * @create 2018/5/31 16:00
     **/
    @Override
    public Message updateFinishProject(ProjectCondition projectCondition) {
        Integer flag = finishProjectDao.updateFinishProject(projectCondition);
        if (flag != null) {
            return Message.success().add("100", "成功");
        }
        return Message.fail().add("0901", "查询失败");
    }

    /**
     * @param
     * @Description 条件查询社会实践
     * @author 20155884 王晓阳
     * @methodName queryProject
     * @returnType
     * @create 2018/5/31 16:30
     **/
    @Override
    public Message queryProject(ProjectCondition projectCondition) {
        List<ProjectCondition> projectList = finishProjectDao.queryProject(projectCondition);
        for (ProjectCondition p:projectList) {
            System.out.println("社会实践："+p.toString());
        }
        System.out.println(projectList.size()+"----");
        if (projectList.size() != 0) {
            return Message.success().add("prpjectList", projectList);
        }
        return Message.fail().add("0901", "查询失败");
    }

    /**
     * @param
     * @Description 根据id查看社会实践
     * @author 20155884 王晓阳
     * @methodName
     * @returnType
     * @create 2018/6/1 14:39
     **/
    public Message queryProjectById(ProjectCondition projectCondition){
        ProjectCondition project=finishProjectDao.queryProjectById(projectCondition);
        System.out.println("-queryProjectById-"+project.getProjectName());
        if (project!=null){
            return Message.success().add("project",project);
        }
        return Message.fail();
    }
}
